package com.ws.shop.action.admin;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.ws.shop.bean.Page;
import com.ws.shop.service.PunchService;
import com.ws.shop.util.DateUtil;
import com.ws.shop.util.RequestUtil;

@Controller
@RequestMapping(value="/admin/punch/*")
public class PunchAction extends BaseAdminAction{
	private static Logger log = Logger.getLogger(PunchAction.class);
	@Autowired
	private PunchService punchService;
	
	@RequestMapping(value="index.jhtml",method=RequestMethod.GET)
	public String index(HttpServletRequest request,Model model){
		String start = RequestUtil.getStringParameter(request, "start", null);
		String end = RequestUtil.getStringParameter(request, "end", null);
		String q_name = RequestUtil.getStringParameter(request, "q_name", null);
		int pageno = RequestUtil.getIntParameter(request, Page.PAGE_NO, 1);
		if(start == null){
			start = DateUtil.dateToString(new Date(),DateUtil.YYYY_MM_DD);
		}
		if(end == null){
			end = DateUtil.dateToString(new Date(),DateUtil.YYYY_MM_DD);
		}
		Page page = punchService.findPunchListByPage(pageno,0,start,end,q_name);
		model.addAttribute("start", start);
		model.addAttribute("end", end);
		model.addAttribute("q_name", q_name);
		model.addAttribute(Page.PAGE, page);
		return "punch_index";
	}

}
